* Motivational figures
preserve


local folder "background_figs"
capture mkdir "${base_dir}/results/`folder'"

local xline_opts_q = "xline(`=eca1qy' `=eca2qy' , lpattern(dash) lcolor(black) ) " 
local xline_opts_m = "xline(`=eca1my' `=eca2my' , lpattern(dash) lcolor(black) ) " 

*local lopts lop( 1 lpat(solid); 2 lpat(dash); 3 msym(D) ) // nomark
local lopts lop( 1 msym(O); 2 msym(D); 3 msym(T) ) // nomark

capture drop tmp_samp
*gen tmp_samp  = (main_sample) & (eca_ind<=2) & (interp_flag==0) & WCport==1
gen tmp_samp  = (bad_months==0)  & (dist_time_outlier==0)  & (eca_ind<=2) & (interp_flag==0) & WCport==1
*** Removing interpolated tracks to avoid double counting
*** dropping bad months because these will exhibit very low vessel counts

* main sample will drop a lot of tracks for which we do not have fuel consumption
* because we don't know vessel characteristics
* We therefore lose a big chunk of fuel consumption starting in 2010
* therefore fill t/km for those with missing values using speed, length, type and qy

* predicting t/km
capture drop tkm_eca09_fitted f_eca09_fitted f_eca09_adjusted
reg tkm_eca09_cons c.avg_speed_eca2009##c.length##i.vesseltype##i.qy  if eca_ind<=2 & exposed
predict tkm_eca09_fitted , xb
gen f_eca09_fitted = dist_eca2009 * tkm_eca09_fitted
gen f_eca09_adjusted = f_eca09_cons
replace f_eca09_adjusted=f_eca09_fitted if f_eca09_cons==.

capture drop f_eca09_main 
gen f_eca09_main = f_eca09_cons if main_sample

capture drop tmp_vess_type
gen tmp_vess_type = vesseltype_reg
replace tmp_vess_type=4 if vesseltype_reg==.

/*
* fuel consumption in eca
lgraph f_eca09_adjusted  my  if tmp_samp , stat(sum) ///
	name(fuel_in, replace) `xline_opts_m' ylab(,nogrid) xtitle("") /// 
	ytitle("Tons") legend(cols(3)) `lopts'
graph export "`folder'\fuel_ineca.eps" , replace
	
* tracks in ECA	
lgraph in_eca09  my  if tmp_samp , stat(sum) ///
	name(cnt_in, replace) `xline_opts_m' ylab(,nogrid) xtitle("") /// 
	ytitle("Voyages") legend(cols(3)) `lopts'
graph export "`folder'\count_ineca.eps" , replace
*/
	
* fuel consumption in eca by vessel type
lgraph f_eca09_adjusted my vesseltype_reg_filled if tmp_samp , stat(sum) ///
	name(fuel_in_ves, replace) `xline_opts_m' ylab(,nogrid) xtitle("") /// 
	ytitle("Tons") legend(cols(3)) `lopts'
graph export "`folder'\fuel_ineca_ves.eps" , replace
	
/*
* vessel counts in eca by vessel type
lgraph in_eca09 my vesseltype_reg_filled if tmp_samp , stat(sum) ///
	name(cnts_in_ves_filled, replace) `xline_opts_m' ylab(,nogrid) xtitle("") /// 
	ytitle("Voyages") legend(cols(3)) `lopts'
graph export "`folder'\count_ineca_ves.eps" , replace	

lgraph in_eca09 my vesseltype_reg if tmp_samp , stat(sum) ///
	name(cnts_in_ves, replace) `xline_opts_m' ylab(,nogrid) xtitle("") /// 
	ytitle("Voyages") legend(cols(3)) `lopts'
*/
	
* very slow moving containers
lgraph super_slow qy if main_sample & eca_ind<=2 & vesseltype_regstr=="Container" & tmp_samp & route_type=="Coastal",  stat(mean) /// 
	name(speed_trends, replace) `xline_opts_q' ylab(,nogrid) ytitle("Fraction Very Slow") xtitle("") legend(cols(3))
	graph export "`folder'\super_slow_cont_CA.eps", replace		


drop tmp_samp

restore
